// components/home-bottom-tab/index.js

Component({
  
  /**
   * 组件的属性列表
   */
  properties: {
    isStatus: {
      type: String,    // 指定类型
      value: ''       // 默认值
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    workList:[],
    color:{
      "待接单":"#FF851A",
      "待处理":"#FF851A",
      "逾期":"#FFFFFF",
      "已办结":"#8ED16D"
    },
    bgColor:{
      "待接单":"#FFF4E8",
      "待处理":"#FFF4E8",
      "逾期":"#fa624b",
      "已办结":"#f0f9eb"
    },
    tabColor:{
      "请假":"#FF851A",
      "工单报障":"#2B62FD",
      "其他类型":"#2B62FD"
    },
    tabBorColor:{
      "请假":"#f8d8bc",
      "工单报障":"#becdf8",
      "其他类型":"#becdf8"
    },
    tabBgColor:{
      "请假":"#FFF4E8",
      "工单报障":"#E8EEFF",
      "其他类型":"#E8EEFF"
    }
  },
// 组件挂载时触发
lifetimes:{
attached() {
  this.handleWork();
},
},
observers: {
  'isStatus': function(newVal) {
    console.log('状态变化:', newVal);
    this.handleWork();
  }
},
  /**
   * 组件的方法列表
   */
  methods: {
    refreshData() {
      // 这里写具体的数据加载逻辑
      this.handleWork()
      console.log('底部标签数据刷新');
    },
    async  handleWork(){
      const { isStatus } = this.properties 
        let data=[];
        if(isStatus ===''||!isStatus){
          const res =await getApp().db.collection('work').where({}).get()
          console.log('获取数据',res);
          data=res.data
        }else if(isStatus==='unFinish'){
          const res1=await getApp().db.collection('work').where({
            status:'待处理'
          }).get()
          const res2=await getApp().db.collection('work').where({
            status:'待接单'
          }).get()
          data=res1.data.concat(res2.data)
        }else if(isStatus==='finish'){
          const res3=await getApp().db.collection('work').where({
            status:'已办结'
          }).get()
          data=res3.data
        }
        else{
          const res4=await getApp().db.collection('work').where({
            status:'逾期'
          }).get()
          data=res4.data
        }
        this.setData({
          workList:data
        })
          
    },
    handleContent(ev){
      console.log('求id',ev);
      let id=ev.currentTarget.dataset.id
      console.log("路由传递id",id);
      wx.navigateTo({
        url: `/package_work/pages/workContent/index?`+`id=${id}`,
      })
    }
  }
})